package com.vincent.message;

import com.vincent.common.Command;
import com.vincent.common.Message;
import com.vincent.common.MessageType;
import com.vincent.utils.BallotNumber;

/**
 * Created by wensen on 2016/12/7.
 * Paxos算法第二阶段中，由Commander发送给Acceptors的消息
 * 带有ballot和slot以及command
 */
public class P2aMessage extends Message{

    //选票
    private final BallotNumber ballot_number;
    //槽
    private final long slot_number;
    //客户端发送的命令
    private Command command;

    public P2aMessage(int src, BallotNumber ballot, long slot, Command cmd) {
        super(src);
        this.ballot_number = ballot;
        this.slot_number = slot;
        this.command = cmd;
    }

    public BallotNumber ballot_number() {
        return this.ballot_number;
    }

    public long slot_number() {
        return this.slot_number;
    }

    public Command command() {
        return this.command;
    }

    public int messageType() {
        return MessageType.P2A_MESSAGE;
    }

    public String toString() {
        return "{P2aMessage[ballot: " + ballot_number +
                " slot: " + slot_number +
                " command: " + command + "]}";
    }

}
